package com.kly.user.db.dao.impl;
import com.fqgj.common.base.AbstractBaseMapper;
import com.fqgj.common.utils.CollectionUtils;
import com.google.common.collect.Maps;
import com.kly.user.db.dao.UserPreHomepageDao;
import com.kly.user.db.entity.UserPreHomepageEntity;
import org.springframework.stereotype.Repository;

import java.util.Date;
import java.util.List;
import java.util.Map;
import java.util.Objects;

/**
* User: linqu
* Date: 2023-08-08
* Time: 17:46:55.391
*/

@Repository
public class UserPreHomepageDaoImpl extends AbstractBaseMapper<UserPreHomepageEntity> implements UserPreHomepageDao {

    @Override
    public int batchInsert(List<UserPreHomepageEntity> userPreHomepageEntityList) {
        if (CollectionUtils.isEmpty(userPreHomepageEntityList)) {
            return 0;
        }
        return getSqlSession().insert(this.getStatement("batchInsert"), userPreHomepageEntityList);
    }

    @Override
    public UserPreHomepageEntity queryByUserCode(String userCode, String userCodeWlm) {
        Map<String, Object> params = Maps.newHashMap();
        params.put("userCode", userCode);
        params.put("userCodeWlm", userCodeWlm);
        final List<UserPreHomepageEntity> userPreHomepageEntities = selectByParams(params);
        if (CollectionUtils.isEmpty(userPreHomepageEntities)) {
            return null;
        }
        return userPreHomepageEntities.get(0);
    }

    @Override
    public List<UserPreHomepageEntity> queryOnlineUser(String modelUserCode) {
        Map<String, Object> params = Maps.newHashMap();
        params.put("userCodeWlm", modelUserCode);
        return this.getSqlSession().selectList(this.getStatement("queryOnlineUser"), params);
    }

    @Override
    public int updateEffectiveDate(String userCode, String userCodeWlm, Date effectiveDate) {
        Map<String, Object> params = Maps.newHashMap();
        params.put("userCode", userCode);
        params.put("userCodeWlm", userCodeWlm);
        params.put("effectiveDate", effectiveDate);
        return this.getSqlSession().update(this.getStatement("updateEffectiveDate"), params);
    }

    @Override
    public int removeRemoveUnEffectiveRecord() {
        return this.getSqlSession().delete(this.getStatement("removeRemoveUnEffectiveRecord"));
    }

    @Override
    public List<UserPreHomepageEntity> queryOverEffectiveRecord() {
        return getSqlSession().selectList(this.getStatement("queryOverEffectiveRecord"), null);
    }


}